package LeetCode.BitCompute;

public class Test12 {
    public static int maxProduct(String[] words) {
        int[] bitArr = new int[words.length];//单词比特数组，存在为1，没有为0
        int i = 0;
        for (String str : words) {
            char[] chars=new char[26];//代表26个字母
            for (char c : str.toCharArray()) {
                chars[c - 'a'] = '1';
            }
            for (int j = 0; j <chars.length ; j++) {
                if (chars[j]!='1') chars[j]='0';
            }
//            //验证01存储
//            for (int j = 0; j <chars.length ; j++) {
//                System.out.print(chars[j]);
//            }
//            System.out.println();
            bitArr[i++]=Integer.parseInt(String.valueOf(chars),2);
        }
        int result=0;
        for (int j = 0; j < bitArr.length; j++) {
            for (int k = j+1; k < bitArr.length; k++) {
                if ((bitArr[j]&bitArr[k])==0)//相与为0说明没有相同的字母
                result=Math.max(result,words[j].length()*words[k].length());
            }
        }
        return result;
    }

    public static void main(String[] args) {
        String[] words={"abcw","baz","foo","bar","xtfn","abcdef"};
        System.out.println(maxProduct(words));
    }
}
